<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
      <p> <input type="text" value=""> 输入数字求和, 数字之间用半角 "," 号分隔</p>
      <button>求和</button> <span class="sp0"></span>
    <script>
    var va2=document.querySelector('input')
    var bt1=document.querySelector('button')
    var ap0=document.querySelector('.sp0')
    bt1.onclick=function(){ 
        console.log(va2.value)
        let a=va2.value.split(',')
        let b=0 
        console.log(a)
        for(let i=0;i<a.length;i++){
            console.log(isNaN(a[i]))
            if(isNaN(a[i])==false){
                b+=Number(a[i])
            }
            
        }
        ap0.innerHTML=b
        
    }

    </script>
</body>
</html>